/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplemetrosystem.view.action;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import simplemetrosystem.control.EditCommandManager;
import simplemetrosystem.control.ElementManager;
import simplemetrosystem.view.MetroFrame;
import simplemetrosystem.model.Element.MetroStation;
import simplemetrosystem.view.InformationPane;
import simplemetrosystem.view.table.Exceptions.InformationPanelException;

/**
 *
 * @author Eric Qian
 */
public class RemoveStationActionListener implements ActionListener {

    /**
     * 
     * @param frame
     * @param station 
     */
    public RemoveStationActionListener(MetroFrame frame, MetroStation station) {
        this.frame = frame;
        this.station = station;
    }

    /**
     * 
     * @param e
     */
    public void actionPerformed(ActionEvent e) {
        if (station != null && frame.getInfPane().getElemTab() == InformationPane.STATION) {
            System.out.println("Remove " + station.getDisplayName());
            EditCommandManager.getInstance().removeStation(station);
            try {
                frame.getInfPane().setFocus(InformationPane.ALL_STATION, null);
            } catch (InformationPanelException ex) {
                ex.printStackTrace();
            }
        } else {
            int selectRow = frame.getInfPane().getAllStationTable().getSelectedRow();
            if (selectRow > -1) {
                station = ElementManager.getInstance().getStationAt(selectRow);
                System.out.println("Remove " + station.getDisplayName());
                EditCommandManager.getInstance().
                        removeStation(station);
            } else {
                System.out.println("Remove Null");
            }
        }
    }
    private MetroFrame frame;
    private MetroStation station;
}

